package com.cw.demo.tomcat.servlet;

import java.io.OutputStream;

import com.cw.demo.tomcat.http.Request;
import com.cw.demo.tomcat.http.Response;

/**
 * TODO
 *
 * @author chenw
 * @date 2021/2/3
 */
public class UserServlet extends MyHttpServlet{
    @Override
    public void doGet(Request request, Response response) {
        this.doPost(request,response);
    }

    @Override
    public void doPost(Request request, Response response) {
        try{
            //省略业务调用的代码，tomcat会根据request对象里面的inputStream拿到对应的参数进行解析
            //模拟业务层调用后的返回
            OutputStream outputStream = response.outputStream;
            String result = Response.responsebody + "success";
            outputStream.write(result.getBytes());
            outputStream.flush();
            outputStream.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void init() throws Exception {

    }

    @Override
    public void destory() {

    }
}
